package com.twang.stock.controller;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.twang.stock.dto.EmailMessage;
import com.twang.stock.entity.CompanyStockMinutes;
import com.twang.stock.entity.LongHuInfo;
import com.twang.stock.mapper.CompanyStockMinutesMapper;
import com.twang.stock.redis.RedisUtil;
import com.twang.stock.rocketMq.RocketMQProducer;
import com.twang.stock.service.CompanyStockMinutesService;
import com.twang.stock.service.LongHuBangService;
import com.twang.stock.service.TodayReDuOnehourService;
import com.twang.stock.service.ZhangTingBanTaskService;
import com.twang.stock.service.jinyan.GetStockListService;
import com.twang.stock.service.jinyan.UpdateAndFixDataService;
import com.twang.stock.service.jinyan.UpdtePriceAndVolService;

import com.twang.stock.strategy.Stock60DayMaxVol;
import com.twang.stock.task.*;
import com.twang.stock.threadPool.AsycTaskExecutorConfig;
import com.twang.stock.utils.http.HttpStockUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/utils")
@Slf4j
public class  UtilController {

    @Autowired
    private ZhangTingBanTask zhangTingBanTask;
    @Autowired
    private StockMinutesTask stockMinutesTask;

    @Autowired
    private NotifyStockBuyTask notifyStockBuyTask;

    @Autowired
    private LongHUDataTask longHUDataTask;

    @Autowired
    private RocketMQProducer rocketMQProducer;

    @Autowired
    private  MinutesStockFixTask minutesStockFixTask;

    @Autowired
    private  ZhangTingJuJiaoJobTask zhangTingJuJiaoJobTask;

    @Autowired
    public FuPanTask fuPanTask;

    @Autowired
    public  StockLastChengJiaoETask stockLastChengJiaoETask;


    @Autowired
    private TodayReDuOnehourService todayReDuOnehourService;

    @Autowired
    private TodayReDuOnehourTask todayReDuOnehourTask;

    @RequestMapping(value = "/minutesStockFixTask")
    public String minutesStockFixTask() throws Exception {
//        rocketMQProducer.sendOneWay("----->>>test---->>>");
        minutesStockFixTask.initMinutesDataNew();
        return  "大盘温度预警";
    }

    @RequestMapping(value = "/todayReDuOnehourTask")
    public String todayReDuOnehourTask() throws Exception {
//        rocketMQProducer.sendOneWay("----->>>test---->>>");
        todayReDuOnehourTask.excute();
        return  "消息刷新";
    }


    @RequestMapping(value = "/todayReDuOnehourService")
    public String todayReDuOnehourService() throws Exception {
        todayReDuOnehourService.excute();
        return  "todayReDuOnehourService success";
    }





    @RequestMapping(value = "/adminFuPan")
    public String adminFuPan() throws Exception {
      //  fuPanTask.adminFuPan("wangtao_27520@qq.com");
        EmailMessage emailMessage = new EmailMessage();
        emailMessage.setCode("000001");
        emailMessage.setName("大盘量能");
        emailMessage.setMessage(">>>>>>>>test");
        emailMessage.setUserId(Long.valueOf(1));
        emailMessage.setType("1");
        log.info(">>>>>>>>>>> 异动预警 emailMessage={}", JSONObject.toJSONString(emailMessage));
        rocketMQProducer.sendOneWay(JSONObject.toJSONString(emailMessage));
        return  "大盘温度预警";
    }
    @RequestMapping(value = "/longHUDataTask")
    public String longHUDataTask() throws Exception {
        longHUDataTask.exceuteToDayLongHuData();
        return  "大盘温度预警";
    }

    /**
     *  http://127.0.0.1:8081/utils/queryZhangDieTingTask
     * @return
     */
    @RequestMapping(value = "/queryZhangDieTingTask")
    @ResponseBody
    public String queryZhangDieTingTask() {
        List list = Lists.newArrayList();
        try {
            zhangTingJuJiaoJobTask.extracted();
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return JSONObject.toJSONString(list);
    }

    /**
     *  http://127.0.0.1:8081/utils/queryZhangDieTingTask
     * @return
     */
    @RequestMapping(value = "/zhangTingJuJiaoJobTask")
    @ResponseBody
    public String zhangTingJuJiaoJobTask() {
        List list = Lists.newArrayList();
        try {
            zhangTingJuJiaoJobTask.extracted();
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return JSONObject.toJSONString(list);
    }

    /**
     *  http://127.0.0.1:8081/utils/notifyStockBuyTask
     * @return
     */
    @RequestMapping(value = "/notifyStockBuyTask")
    @ResponseBody
    public String notifyStockBuyTask() {
        List list = Lists.newArrayList();
        try {
            notifyStockBuyTask.刷新数据();
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return JSONObject.toJSONString(list);
    }

    /**
     *  http://127.0.0.1:8081/utils/notifyStockBuyTask
     * @return
     */
    @RequestMapping(value = "/stockMinutesTask")
    @ResponseBody
    public String stockMinutesTask() {
        List list = Lists.newArrayList();
        try {
            stockMinutesTask.涨停板连扳数据();
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return JSONObject.toJSONString(list);
    }

    /**
     *  http://127.0.0.1:8081/utils/notifyStockBuyTask
     * @return
     */
    @RequestMapping(value = "/zhangTingBanTask")
    @ResponseBody
    public String zhangTingBanTask() {
        List list = Lists.newArrayList();
        try {
            zhangTingBanTask.insertZhangTingBanData(null);
        } catch (Exception e) {
            log.error("CalculationController.count exception={}", e);
        }
        return JSONObject.toJSONString(list);
    }

    /**
     *  http://127.0.0.1:8081/utils/stockLastChengJiaoETask
     * @return
     */
    @RequestMapping(value = "/stockLastChengJiaoETask")
    @ResponseBody
    public String stockLastChengJiaoETask() {
        stockLastChengJiaoETask.excute();
        return "OK";
    }





    public static void main(String[] args) throws IOException {

    }

}
